
//  Created by 杨春至 on 2017/12/14.
//  Copyright © 2017年 ZhongZeng. All rights reserved.
//

#import "ForgetFirstVC.h"
#import "ZZHelper.h"
#import "ZZLForgetVC.h"
@interface ForgetFirstVC ()

@end

@implementation ForgetFirstVC

- (void)viewDidLoad {
    K_WS(weakSelf);
    [super viewDidLoad];
    self.title = @"忘记密码";

    [self.nextStepBtn bk_whenTapped:^{
        if ([self checkTelephoneValid:self.vadidateCodeTF.text]) {
            [weakSelf getCodeNetWorking];
        }
        else
        {
            [QMUITips showError:@"请输入正确的手机号码" inView:self.view hideAfterDelay:1.8];
        }
    }];
    //复用界面,这里面是获取验证码
 
    // Do any additional setup after loading the view from its nib.
}
- (void)getCodeNetWorking
{
       K_WS(weakSelf);
    [NetWorkingManager postWithRequestUrl:@"findPwdSendYzm" AndParameters:@{@"parameters":[@{@"username":self.vadidateCodeTF.text,@"type":@"2",@"imageCode":@"",@"phoneId":[ZZHelper deviceIPAdress],@"uCode":[ZZHelper ucode]} DataTOjsonStringAndAddVersion]} AndRequestBlock:^(NSDictionary *responseObject) {
        NSString *str = responseObject[@"end"];
        if ([str isEqualToString:@"ok"]) {
            ZZLForgetVC *forgetVC = [[ZZLForgetVC alloc]initWithNibName:@"ZZLForgetVC" bundle:nil];
            forgetVC.phoneStr = self.vadidateCodeTF.text;
            [weakSelf.navigationController pushViewController:forgetVC animated:YES];
        }
    } FailBlock:^(NSDictionary *errDic) {
        
    }];
}

- (void)validateNetworking
{
    [NetWorkingManager postWithRequestUrl:@"findPwdYzmIsRight" AndParameters:@{@"parameters":[@{@"username":self.phoneStr,@"yzm":self.vadidateCodeTF.text,@"type":@"2",@"phoneId":[ZZHelper deviceIPAdress]} DataTOjsonStringAndAddVersion]} AndRequestBlock:^(NSDictionary *responseObject) {
        
    } FailBlock:^(NSDictionary *errDic) {
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/**
 *  检验手机号码有效性
 */
- (BOOL)checkTelephoneValid:(NSString *)mobile{
    NSString *mobileRegex = @"^((13[0-9])|(147)|(17[0-9])|(15[^4,\\D])|(18[^4]))\\d{8}$";
    NSPredicate *mobileTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",mobileRegex];
    return [mobileTest evaluateWithObject:mobile];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
